package at.fhj.itm10.ticketmaster.beans;

/**
 * @author Christopher Barilich
 * 
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.faces.bean.RequestScoped;

import at.fhj.itm10.ticketmaster.dao.DAOException;
import at.fhj.itm10.ticketmaster.dao.EventTypeDAO;
import at.fhj.itm10.ticketmaster.dao.impl.DAOFactoryImpl;
import at.fhj.itm10.ticketmaster.models.Address;
import at.fhj.itm10.ticketmaster.models.EventType;

@ManagedBean
@RequestScoped
public class EventTypeBean {

	private EventTypeDAO dao;

	private int id;
	private String category;
	private List<EventType> allCategories = new ArrayList<EventType>();
	
	private HashMap<String, EventType> eventtypes = new HashMap<String, EventType>();


	public EventTypeBean() {

		super();
		init();

	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public List<EventType> getAllCategories() {
		return allCategories;
	}

	public EventTypeDAO getDao() {
		return dao;
	}

	public void setDao(EventTypeDAO dao) {
		this.dao = dao;
	}

	public void setAllCategories(List<EventType> allCategories) {
		this.allCategories = allCategories;
	}

	@PostConstruct
	public void init() {
		try {
			// getDAO
			DAOFactoryImpl dfi = new DAOFactoryImpl();
			setDao(dfi.getEventTypeDAO());

			allCategories = dao.findAll();
			
			initTypes();
			
			
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
	}
	
	//@author: schure
	
	public void initTypes() 
	{
		
		EventType et;
		
		for(int i=0; i < allCategories.size(); i++) 
		{
			et= allCategories.get(i);
			
			eventtypes.put((Long.toString(et.getId())), et);
		}
		
	}
	
	public EventType showEventtypeInfos(String id) {
		EventType eventType = null;
		
		if(eventtypes.containsKey(id)) {
			eventType = eventtypes.get(id); 
			
		} else {
			System.err.println("ERROR: No fff with this id -> " + id + "!");
		}
		
		return eventType;
	}

}
